﻿Public Class FormInto
    Private WithEvents UcDigitalKeyboard1 As ucDigitalKeyboard
    Public usr As String
    Dim objJlMst As New clsJlMst
    Dim objFactory0utsourceMst As New clsFactory0utsourceMst
    Dim objAutoNumber As New clsAutoNumber
    Private Sub FormInto_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        setForm()
    End Sub

    Private Sub setForm()
        txtBatchNo.Text = String.Empty
        Dim dtJlMst As DataTable = objJlMst.getList()
        cmb_type.DisplayMember = "mst_value"
        cmb_type.ValueMember = "mst_value"
        cmb_type.DataSource = dtJlMst
        If dtJlMst.Rows.Count > 0 Then
            cmb_type.SelectedIndex = 0
        End If
        shchdt.Text = Now().ToShortDateString()
        rkdt.Text = Now().ToShortDateString()
        rk_weight.Value = 0
        Dim dtFactory0utsourceMst As DataTable = objFactory0utsourceMst.getList("2")
        cmb_factory.DisplayMember = "name"
        cmb_factory.ValueMember = "name"
        cmb_factory.DataSource = dtFactory0utsourceMst
        If dtFactory0utsourceMst.Rows.Count > 0 Then
            cmb_factory.SelectedIndex = 0
        End If
        txtBatchNo.Select()
    End Sub

    Private Sub txt_MouseDown(sender As Object, e As MouseEventArgs) Handles rk_weight.MouseDown
        UcDigitalKeyboard1 = New ucDigitalKeyboard
        If sender.MaskBox.Mask.EditMask = "d" Then
            UcDigitalKeyboard1.B_01 = False
        Else
            UcDigitalKeyboard1.B_01 = True
        End If

        If sender.GetType().Name.Equals("TextEdit") Then
            UcDigitalKeyboard1.B_02 = True
        Else
            UcDigitalKeyboard1.B_02 = False
        End If

        UcDigitalKeyboard1.Txt = sender

        Me.Controls.Add(UcDigitalKeyboard1)
        UcDigitalKeyboard1.Show()
        UcDigitalKeyboard1.BringToFront()
        UcDigitalKeyboard1.Focus()
    End Sub

    Private Sub btnInto_Click(sender As Object, e As EventArgs) Handles btnInto.Click
        If String.IsNullOrEmpty(txtBatchNo.Text.Trim()) Then
            MsgBox("请输入批次号", vbYes, "提示")
            Exit Sub
        End If
        If rk_weight.Value <= 0 Then
            MsgBox("入库重量需大于0", vbYes, "提示")
            Exit Sub
        End If
        If MsgBox("确认要进行入库吗？", vbYesNo, "提示") = vbYes Then
            Dim code As String = Now.ToString("yyyyMMdd") & "-" & objAutoNumber.getNextKeyNo("jl_rk_code", "jlrkAutoNumber")
            Dim en As New entityjl_rk
            en.batch_no = txtBatchNo.Text.Trim()
            en.mst_value = cmb_type.Text
            en.production_date = shchdt.Text
            en.into_date = rkdt.Text
            en.into_weight = rk_weight.Value
            en.assist_marker = cmb_factory.Text
            en.location = String.Empty
            en.validity = "1"
            Dim rtn As Integer = objJlMst.intoCk(code, en, usr)
            If rtn <> -2 Then
                objAutoNumber.setNextKeyNo("jl_rk_code", "jlrkAutoNumber")
                MsgBox("入库成功", vbYes, "提示")
                setForm()
                CType(Owner, FormMain).initData()
            Else
                MsgBox("入库失败", vbYes, "提示")
            End If

        End If
    End Sub
End Class